import gc
import os
import random
import threading
import time,datetime,sys
from selenium import webdriver
import unittest
from pywinauto.application import Application
from psutil import process_iter
from pywinauto import mouse
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import traceback
import tools
# import pytest
from tools import *

class ParametrizedTestCase(unittest.TestCase):
    """ TestCase classes that want to be parametrized should
        inherit from this class.
    """

    def __init__(self, methodName='runTest', param=None):
        super(ParametrizedTestCase, self).__init__(methodName)
        self.param = param

    @staticmethod
    def parametrize(testcase_class, param=None):
        """ Create a suite containing all tests taken from the given
            subclass, passing them the parameter 'param'.
        """
        testloader = unittest.TestLoader()
        testnames = testloader.getTestCaseNames(testcase_class)
        suite = unittest.TestSuite()
        for name in testnames:
            suite.addTest(testcase_class(name, param=param))
        return suite
class Global_Lock:
    sent_pic_lock = threading.Lock()

class investment_manager(ParametrizedTestCase):

    def run_start(self, driver, channelShopId):
        self.login_wechat_shop(driver, channelShopId)
        if self.to_optimal_alliance(driver, channelShopId):
            self.to_business_manager(driver, channelShopId)
        else:
            while not self.to_optimal_alliance(driver, channelShopId):
                time.sleep(20)
                send_person_msg('17326075282', channelShopId, '登录后检测视频号id对比失败', '请检查视频号小店扫码使用了正确的微信')
        # 开始执行
        while 1:
            try:
                # 获取当前时间
                currentMinutes = int(datetime.datetime.now().strftime('%M'))
                if currentMinutes % random.randint(2, 8) == 0:
                    self.check_login_status(driver, channelShopId)
                    time.sleep(20)
                elif currentMinutes % 5 == 0:
                    if self.to_optimal_alliance(driver, channelShopId):
                        time.sleep(30)
                        self.to_business_manager(driver, channelShopId)
                    else:
                        while not self.to_optimal_alliance(driver, channelShopId):
                            time.sleep(20)
                            send_person_msg('17326075282', channelShopId, '登录后检测视频号id对比失败', '请检查视频号小店扫码使用了正确的微信')
                elif currentMinutes % 2 == 0:
                    self.sent_machine_status(channelShopId)
                else:
                    print("登录状态良好")
                gc.collect()
                self.add_invest_good_flow(driver, channelShopId)

            except Exception as e:
                print("driver is:%s" % driver)
                gc.collect()
                send_group_msg(channelShopId, "run_start步骤异常", e)
                self.run_start(driver, channelShopId)

    def add_invest_good_flow(self, driver, channelShopId):
        print("start add_invest_good_flow")
        try:
            sx_ret = getTask(channelShopId)
            # sx_ret['data']['channelShopId']='wx0829c079cc4ca92a'
            # sx_ret['data']['productId']='10000020128181'
            while sx_ret != None:
                if 'data' in sx_ret.keys():
                    if channelShopId == sx_ret['data']['channelShopId']:
                        self.g['channelShopId'] = sx_ret['data']['channelShopId']
                        self.g['productId'] = sx_ret['data']['productId']
                        self.to_business_manager(driver, channelShopId)
                        self.add_invite_goods(driver, self.g['productId'], channelShopId)
                        self.g = {}
                        sx_ret = getTask(channelShopId)
                    else:
                        self.g = {}
                        sx_ret = getTask(channelShopId)
                else:
                    break
        except Exception as e:
            send_error_msg(channelShopId, "add_invest_good_flow: ", e)
            driver.refresh()




    def login_wechat_shop(self, driver, channelShopId):
        # 登录视频号小店
        try:
            print("开始登录视频号小店")
            driver.refresh()
            driver.get("https://channels.weixin.qq.com/shop")
            time.sleep(5)
            driver.maximize_window()
            driver.implicitly_wait(10)
            print("爱逛管理员请扫码")
            # 判断是否需要扫码登录
            if is_element_exist_css(driver, ".login__type__container__scan__qrcode"):
                time.sleep(5)
                wechat_shop_QR_code = driver.find_element(By.CSS_SELECTOR ,".login__type__container__scan__qrcode")
                wechat_shop_QR_code_path = tools.scan_pic_path + 'login_qrcode\\' + '_login_' + time.strftime(
                    "%Y-%m-%d-%H_%M_%S", time.localtime(time.time())) + ".png"
                wechat_shop_QR_code.screenshot(wechat_shop_QR_code_path)
                # 发送二维码给对应微信，微信昵称备注为视频号小店id
                time.sleep(2)
                self.sent_pic(channelShopId, wechat_shop_QR_code_path)
                os.remove(wechat_shop_QR_code_path)
                time.sleep(2)
            # 判断是否扫码成功
            pointer = 1
            while 1 == 1:
                if is_element_exist_css(driver, ".can-hover"):
                    break
                else:
                    print("正在等待爱逛管理员请扫码")
                    time.sleep(2)
                    pointer += 1
                    if pointer == 150:
                        self.login_wechat_shop(driver,channelShopId)
            print("登录成功")
        except Exception as e:
            send_group_msg("登录", "login_wechat_shop登录视频号小店", e)
            self.login_wechat_shop(driver, channelShopId)

    def check_login_status(self,driver,channelShopId):
        # check登录状态
        print("开始check_login_status")
        try:
            driver.refresh()
            time.sleep(5)
            if is_element_exist_css(driver, ".can-hover"):
                print("已经是登录状态")
            elif is_element_exist_css(driver, "#body > div > div > div > div > h2 > a"):
                    print("登录态失效，爱逛管理员请扫码")
                    driver.find_element(By.CSS_SELECTOR, "#body > div > div > div > div > h2 > a").click()
                    time.sleep(3)
                    wechat_shop_QR_code = driver.find_element(By.CSS_SELECTOR ,".login__type__container__scan__qrcode")
                    wechat_shop_QR_code_path = tools.scan_pic_path + 'login_qrcode\\' + '_login_' + time.strftime(
                        "%Y-%m-%d-%H_%M_%S", time.localtime(time.time())) + ".png"
                    wechat_shop_QR_code.screenshot(wechat_shop_QR_code_path)
                    # 发送二维码给对应微信，微信昵称备注为视频号小店id
                    time.sleep(random.randint(30, 60))
                    self.sent_pic(channelShopId, wechat_shop_QR_code_path)
                    # 判断是否扫码成功
                    pointer = 1
                    while 1 == 1:
                        if is_element_exist_css(driver, ".can-hover"):
                            break
                        else:
                            print("等待爱逛管理员请扫码")
                            time.sleep(2)
                            pointer += 1
                            if pointer == 150:
                                self.login_wechat_shop(driver,channelShopId)
                    print("扫码登录成功")
            elif is_element_exist_css(driver, "#app > div > div.login-view > div.login-content > div.login-qrcode-wrap > div > div.qrcode-wrap > img"):
                driver.get("https://channels.weixin.qq.com/shop/shopleague/head-supplier")
                time.sleep(3)
                self.check_login_status(driver, channelShopId)
            else:
                driver.refresh()
        except Exception as e:
            send_group_msg("登录", "check_login_status登录视频号小店", e)
            self.login_wechat_shop(driver, channelShopId)

    # 进入优选联盟->店铺管理->基础信息 判断小店信息是否正确
    def to_optimal_alliance(self, driver, channelShopId):
        # return True
        try:
            # 判断是否打开店铺管理二级目录
            print("to_optimal_alliance-》进入优选联盟->店铺管理->基础信息 判断小店信息是否正确")
            if is_element_exist_css(driver, "#menuBar .weui-desktop-menu_:nth-of-type(2) > .weui-desktop-menu__link:nth-of-type(1)"):
                driver.find_element(By.CSS_SELECTOR, "#menuBar .weui-desktop-menu_:nth-of-type(2) > .weui-desktop-menu__link:nth-of-type(1)").click()
            time.sleep(3)
            print("打开基础信息")
            # 判断登出弹窗的状态
            if is_element_exist_css(driver, "#custom_scan_mask > div > p.login__type__container__scan_mask__refresh > a"):
                driver.refresh()
                time.sleep(10)
                self.check_login_status(driver, channelShopId)
            # 里层需要登录扫码的的弹窗
            elif is_element_exist_css(driver, "#app > div:nth-child(3) > div.weui-desktop-dialog__wrp > div > div.weui-desktop-dialog__bd > div > div.qrcodeContainer > div > img"):
                driver.refresh()
                time.sleep(10)
                self.check_login_status(driver, channelShopId)
            # 最外层登录页面
            elif is_element_exist_css(driver, "#body > div > div > div > div > h2 > a"):
                self.check_login_status(driver, channelShopId)
            else:
                print("是login状态")
            # 打开基础信息
            driver.find_element(By.CSS_SELECTOR,
                                "li:nth-of-type(2) > .weui-desktop-sub-menu.weui-desktop-sub-menu__current > li:nth-of-type(1) > .weui-desktop-menu__link  .weui-desktop-menu__name").click()
            # 切换shadow_driver
            shadow_driver = self.switch_shadow(driver, channelShopId)
            # 获取小店id
            print("通过元素获取小店id")
            if not is_element_exist_css(shadow_driver, "#app > div > div:nth-child(3) > div:nth-child(1) > div > div.loading_content_slot > div:nth-child(2) > div > div.table_wrp > table > tbody > tr:nth-child(1) > td:nth-child(2) > div"):
                driver.refresh()
                time.sleep(10)
            current_shop_id = shadow_driver.find_element(By.CSS_SELECTOR, "#app > div > div:nth-child(3) > div:nth-child(1) > div > div.loading_content_slot > div:nth-child(2) > div > div.table_wrp > table > tbody > tr:nth-child(1) > td:nth-child(2) > div").text
            print("获取到当前视频号小店id为：%s"% current_shop_id)
            time.sleep(10)
            if channelShopId == current_shop_id:
                return True
            else:
                send_group_msg(channelShopId, "判断小店信息是否正确", "视频号小店ID对应不上")
                return False
        except Exception as e:
            send_group_msg(channelShopId, "判断小店基础信息", e)

    # 进入优选联盟->团长托管
    def to_business_manager(self, driver, channelShopId):
        # 判断是否打开优选联盟二级目录
        print("to_business_manager")
        try:
            if is_element_exist_css(driver, "#menuBar > li:nth-child(10) > span.weui-desktop-menu__link.arrow-up"):
                driver.find_element(By.CSS_SELECTOR, "li:nth-of-type(10) > .weui-desktop-sub-menu.weui-desktop-sub-menu__current > li:nth-of-type(2) > .weui-desktop-menu__link  .weui-desktop-menu__name").click()
            else:
                driver.find_element(By.CSS_SELECTOR, "#menuBar > li:nth-child(10) > span").click()
                time.sleep(1)
                driver.find_element(By.CSS_SELECTOR, "li:nth-of-type(10) > .weui-desktop-sub-menu.weui-desktop-sub-menu__current > li:nth-of-type(2) > .weui-desktop-menu__link  .weui-desktop-menu__name").click()
                time.sleep(3)
        except Exception as e:
            send_error_msg(channelShopId, "进入优选联盟->团长托管", e)


    # 切换shadow-root
    def switch_shadow(self, driver, channelShopId):
        try:
            time.sleep(2)
            # 切换到shadow-root
            shadow_driver = driver.execute_script(
                "return document.querySelector('#js_container_box > div.col_main > div.col_main_inner > div:nth-child(2) > div > micro-app').shadowRoot.children[1]")

            time.sleep(2)
            return shadow_driver
        except Exception as e:
            send_error_msg(channelShopId, "切换shadow-root", e)

    # check电脑状态
    def sent_machine_status(self, channelShopId):
        try:
            time.sleep(2)
            # 切换到shadow-root
            post_machine_status(channelShopId)
            time.sleep(2)
        except Exception as e:
            send_error_msg(channelShopId, "check电脑状态", e)

    # 推广团长商品
    def add_invite_goods(self, driver, productId, channelShopId):
        try:
            time.sleep(2)
            # 切换到shadow-root
            shadow_driver = driver.execute_script("return document.querySelector('#js_container_box > div.col_main > div.col_main_inner > div:nth-child(2) > div > micro-app').shadowRoot.children[1]")
            # 进入新增弹窗页面
            shadow_driver.find_element(By.CSS_SELECTOR, "#app > div.weui-desktop-block > div > div > div.flex.justify-between.items-center > div:nth-child(2) > div > button").click()
            # 展开团长下拉列表
            time.sleep(3)
            shadow_driver.find_element(By.CSS_SELECTOR, "#app > div.v-transfer-dom > div.weui-desktop-dialog__wrp.half-dialog > div > div.weui-desktop-dialog__bd > div > div:nth-child(2) > div.mr-12.list-filter-container > div > dl > dt").click()
            # 选中团长
            shadow_driver.find_element(By.CSS_SELECTOR, "#app > div.v-transfer-dom > div.weui-desktop-dialog__wrp.half-dialog > div > div.weui-desktop-dialog__bd > div > div:nth-child(2) > div.mr-12.list-filter-container > div > dl > div:nth-child(2) > ul > li").click()
            # 输入并搜索商品
            shadow_driver.find_element(By.CSS_SELECTOR, "#itemSearchText").click()
            shadow_driver.find_element(By.CSS_SELECTOR, "#itemSearchText").send_keys(productId)
            shadow_driver.find_element(By.CSS_SELECTOR, "#itemSearchText").send_keys(Keys.ENTER)
            time.sleep(2)
            # check 搜索结果
            if is_element_exist_css(shadow_driver, "#app > div.v-transfer-dom > div.weui-desktop-dialog__wrp.half-dialog > div > div.weui-desktop-dialog__bd > div > div.flex.items-start.justify-between > div > div > div > div > div.weui-desktop-table__loading-content__slot > div > div > div > table > tbody > tr:nth-child(2) > td:nth-child(2) > div > div > div"):
                # 如果有结果，选中
                shadow_driver.find_element(By.CSS_SELECTOR, "#app > div.v-transfer-dom > div.weui-desktop-dialog__wrp.half-dialog > div > div.weui-desktop-dialog__bd > div > div.flex.items-start.justify-between > div > div > div > div > div.weui-desktop-table__loading-content__slot > div > div > div > table > tbody > tr:nth-child(2) > td:nth-child(1) > label > i").click()
                #选中之后右侧是否展示出来
                if is_element_exist_css(shadow_driver, "#app > div.v-transfer-dom > div.weui-desktop-dialog__wrp.half-dialog > div > div.weui-desktop-dialog__bd > div > div.flex.items-start.justify-between > div > div > div > div > div.weui-desktop-table__loading-content__slot > div > div > div > table > tbody > tr > td:nth-child(1) > div > div > div"):
                    # 开始选择时间
                    shadow_driver.find_element(By.CSS_SELECTOR, "#app > div.v-transfer-dom > div.weui-desktop-dialog__wrp.half-dialog > div > div.weui-desktop-dialog__bd > div > div:nth-child(2) > div:nth-child(2) > dl > dt > span:nth-child(1) > div > span > input").click()
                    # 点击永久
                    shadow_driver.find_element(By.CSS_SELECTOR, "#app > div.v-transfer-dom > div.weui-desktop-dialog__wrp.half-dialog > div > div.weui-desktop-dialog__bd > div > div:nth-child(2) > div:nth-child(2) > dl > dd > div.weui-desktop-picker__panel.weui-desktop-picker__panel_left-slot > div.weui-desktop-picker__panel__quick-select.weui-desktop-picker__panel__quick-select_time > div").click()
                    # 点击确定
                    shadow_driver.find_element(By.CSS_SELECTOR, "#app > div.v-transfer-dom > div.weui-desktop-dialog__wrp.half-dialog > div > div.weui-desktop-dialog__ft > div > div:nth-child(2) > button").click()
                    time.sleep(1)
                    # check 添加结果
                    self.check_add_goods_result(shadow_driver, productId, channelShopId)
                # 右边没有展示出来，并且提示类目不能添加
                elif shadow_driver.find_element(By.CSS_SELECTOR, "#app > div.v-transfer-dom > div.weui-desktop-dialog__wrp.half-dialog > div > div.weui-desktop-dialog__bd > div > div.flex.items-start.justify-between > div > div > div > div > div.weui-desktop-table__loading-content__slot > div > div > div > table > tbody > tr:nth-child(2) > td:nth-child(2) > div > div > div > div.flex.items-center > div.text-black.opacity-30").text == "该商品所在类目暂不支持推广":
                    update_inve_goods_result(productId, 3)
                # 其他异常情况
                else:
                    update_inve_goods_result(productId, 0)
                    send_error_msg(channelShopId, "新增-搜索商品，选中后商品异常", productId)
            # 搜索商品没有结果，更新为0
            else:
                update_inve_goods_result(productId, 0)
                send_error_msg(channelShopId, "新增-搜索商品，没有找到", productId)
            # check frame弹窗
            # self.check_frame(shadow_driver)
            driver.refresh()

        except Exception as e:
            self.check_frame(shadow_driver)
            send_group_msg(channelShopId, "推广团长商品%s" % productId, e)
            self.to_business_manager(driver, channelShopId)
            driver.refresh()
    # check 添加商品结果
    def check_add_goods_result(self, shadow_driver, productId, channelShopId):
        # 输入商品id
        try:
            shadow_driver.find_element(By.CSS_SELECTOR, "#app > div.weui-desktop-block > div > div > div.flex.justify-between.items-center > div > div:nth-child(1) > div.weui-desktop-form__input-area > span > input").click()
            # 输入视频号id
            shadow_driver.find_element(By.CSS_SELECTOR, "#app > div.weui-desktop-block > div > div > div.flex.justify-between.items-center > div > div:nth-child(1) > div.weui-desktop-form__input-area > span > input").send_keys(productId)
            # 点击搜索
            time.sleep(3)
            shadow_driver.find_element(By.CSS_SELECTOR, "#app > div.weui-desktop-block > div > div > div.flex.justify-between.items-center > div > div:nth-child(1) > div.weui-desktop-form__input-area > span > span > button").click()
            time.sleep(3)
            # 判断是否有【推广中】
            if is_element_exist_css(shadow_driver,"#app > div.weui-desktop-block > div > div > div.table_out.weui-desktop-table_primary > div > div > div.weui-desktop-table__loading-content__slot > div > div > div > table > tbody > tr"):
                if shadow_driver.find_element(By.CSS_SELECTOR, "#app > div.weui-desktop-block > div > div > div.table_out.weui-desktop-table_primary > div > div > div.weui-desktop-table__loading-content__slot > div > div > div > table > tbody > tr > td:nth-child(4) > div > div").text == '合作中':
                    update_inve_goods_result(productId, 2)
                elif shadow_driver.find_element(By.CSS_SELECTOR, "#app > div.weui-desktop-block > div > div > div.table_out.weui-desktop-table_primary > div > div > div.weui-desktop-table__loading-content__slot > div > div > div > table > tbody > tr > td:nth-child(4) > div > div").text == '审核中':
                    print("商品状态是审核中")
                else:
                    # 其他状态
                    update_inve_goods_result(productId, 0)
                    send_error_msg(channelShopId, "添加完成后商品状态不是【合作中】", productId)
            else:
                # 搜索没有结果
                update_inve_goods_result(productId, 0)
                send_error_msg(channelShopId, "添加完成后搜索不到商品", productId)
        except Exception as e:
            send_error_msg(channelShopId, "check_add_goods_result：", e)

    def check_frame(self, shadow_driver):
        # 是否还在添加流程
        if is_element_exist_css(shadow_driver,
                                "#app > div.v-transfer-dom > div.weui-desktop-dialog__wrp.half-dialog > div > div.weui-desktop-dialog__hd > button"):
            shadow_driver.find_element(By.CSS_SELECTOR,
                                       "#app > div.v-transfer-dom > div.weui-desktop-dialog__wrp.half-dialog > div > div.weui-desktop-dialog__hd > button").click()

    # 重新登录
    def relogin(self, driver, channelShopId):
        try:
            # 退出登录
            print("relogin > 重新登录")
            if is_element_exist_css(driver, "#header > div > div > div.header_box_msg > div.header_box_item.personInfo > div"):
                driver.find_element(By.CSS_SELECTOR,
                                    "#header > div > div > div.header_box_msg > div.header_box_item.personInfo > div").click()
                driver.find_element(By.CSS_SELECTOR,
                                "#header > div > div > div.header_box_msg > div.header_box_item.personInfo > div > div > div.info-bounce_bottom > ul > li > i").click()
            time.sleep(1)
            print("爱逛管理员请扫码")
            # 判断是否需要扫码登录
            if is_element_exist_css(driver, ".login__type__container__scan__qrcode"):
                wechat_shop_QR_code = driver.find_element(By.CSS_SELECTOR, ".login__type__container__scan__qrcode")
                wechat_shop_QR_code_path = tools.scan_pic_path + 'login_qrcode\\' + '_login_' + time.strftime(
                    "%Y-%m-%d-%H_%M_%S", time.localtime(time.time())) + ".png"
                wechat_shop_QR_code.screenshot(wechat_shop_QR_code_path)
                # 发送二维码给对应微信，微信昵称备注为视频号小店id
                time.sleep(2)
                self.sent_pic(channelShopId, wechat_shop_QR_code_path)
                time.sleep(2)
            # 判断是否扫码成功
            pointer = 1
            while 1 == 1:
                if is_element_exist_css(driver, ".can-hover"):
                    break
                else:
                    print("正在等待爱逛管理员请扫码")
                    time.sleep(2)
                    pointer += 1
                    if pointer == 150:
                        self.login_wechat_shop(driver, channelShopId)
            print("登录成功")
        except Exception as e:
            send_group_msg(channelShopId, "判断小店基础信息", e)

    def get_pid(self):
        PID = process_iter()
        for pid_temp in PID:
            pid_dic = pid_temp.as_dict(attrs=['pid', 'name'])
            if pid_dic['name'] == 'WeChat.exe':
                return pid_dic['pid']
        else:
            return 0
        print()

    # 左键点击某个控件
    def click_one(self, title='', control_type='', button='left', found_index=0, left=10, top=10, times=1):
        """
        :param title: 控件名称
        :param control_type: 控件类型
        :param button: left right middle 对应左、右、中三个键
        :param times: 点击次数
        :param found_index: 选择同名同类型多个控件中的第几个
        :param left: X 正方向修正
        :param top: Y 正方向修正
        :return:
        """
        # 在这里控件名称和类型，可以只选择一个，不过定位精准度不高
        if title == '' and control_type == '':
            raise ValueError('控件名和控件类型不可为空!')
        position = self.win.child_window(title=title, control_type=control_type, found_index=found_index).rectangle()
        for i in range(times):
            mouse.click(button=button, coords=(position.left + left, position.top + top))
            if times > 1:
                time.sleep(0.2)

    def connect_wechat(self):
        try:
            Application(backend='uia').start('C:\Program Files (x86)\Tencent\WeChat\WeChat.exe')
        except Exception as e:
            print()
        PID = self.get_pid()
        if PID == 0:
            print('未检测到微信运行')
            return 0
        else:
            self.app = Application(backend='uia')
            self.app.connect(process=PID)
            self.win = self.app[u'微信']
            print('已建立与微信链接')
        print()

    def sent_pic(self, channelShopId, path):
        # lock = threading.Lock()
        Global_Lock.sent_pic_lock.acquire()
        self.connect_wechat()
        print("开始发送登录二维码给爱逛管理员")
        wx_name = name_dict.get(channelShopId)
        try:
            while 1 == 1:
                if self.win.child_window(title=wx_name, control_type='Button', found_index=0).exists(timeout=1):
                    print("点击管理员昵称")
                    time.sleep(3)
                    self.click_one(title=wx_name, control_type='Button')
                    time.sleep(1)
                    self.click_one(title="发送文件", control_type='Button')
                    print("点击发送文件")
                    time.sleep(1)
                    try:
                        self.win.child_window(title="文件名(N):", class_name='Edit').type_keys(path)
                        print("输入文件名")
                    except Exception as e:
                        print()
                    time.sleep(1)
                    try:
                        self.win.child_window(class_name='Button', title='打开(O)').click_input()
                        print("点击打开")
                    except Exception as e:
                        print()
                    time.sleep(1)
                    self.click_one(title="sendBtn", control_type='Button')
                    print("点击发送")
                    time.sleep(1)
                    break
                else:
                    print("当前界面未找到微信联系人：%s" % wx_name)
                    time.sleep(random.randint(30, 60))
        except Exception as e:
            print(e)
            send_error_msg(channelShopId, "sent_pic", e)
        Global_Lock.sent_pic_lock.release()

    def test_run(self):
        self.g = globals()
        thread = []
        options = Options()
        options.add_argument("--incognito")
        driver_path = "C:\Python\Python38\Scripts\chromedriver.exe"
        driver_path1 = "C:\Python\Python38\Scripts\chromedriver1.exe"
        driver_path2 = "C:\Python\Python38\Scripts\chromedriver2.exe"
        # driver_path3 = "C:\Python\Python38\Scripts\chromedriver3.exe"


        driver = webdriver.Chrome(driver_path, options=options)
        driver1 = webdriver.Chrome(driver_path1, options=options)
        driver2 = webdriver.Chrome(driver_path2, options=options)
        # driver3 = webdriver.Chrome(driver_path3, options=options)

        driver.implicitly_wait(10)
        driver1.implicitly_wait(10)
        driver2.implicitly_wait(10)
        # driver3.implicitly_wait(10)

        driverList = [driver, driver1, driver2]
        # 开始执行
        for channelShopId in tools.channelShopIdList:
            driver = driverList[channelShopIdList.index(channelShopId)]
            # self.g['lock'] = threading.Lock()
            thread.append(threading.Thread(target=self.run_start, args=(driver, channelShopId)))


        for t in thread:
            time.sleep(30)
            t.start()

        for t in thread:
            t.join()



    def re_start(self, channelShopId):
        print("开始kill chrome driver，并且重新开始任务")
        options = Options()
        options.add_argument("--incognito")
        driver_path_list = ["C:\Python\Python38\Scripts\chromedriver.exe", "C:\Python\Python38\Scripts\chromedriver1.exe"]
        channelShopIdList = ["wx0829c079cc4ca92a"]
        driver_path = "C:\Python\Python38\Scripts\chromedriver.exe"
        for i in range(0, len(channelShopIdList), 1):
            if channelShopIdList[i] == channelShopId:
                driver_path = driver_path_list[i]
        print("开始重新声明driver")
        driver = webdriver.Chrome(driver_path, options=options)
        print("driver执行完成")
        driver.implicitly_wait(10)
        return driver

